package com.baizan.daka.ui.activity

import android.content.Context
import android.content.Intent
import com.baizan.daka.base.BasePageListActivity
import com.baizan.daka.mvp.model.bean.NewsInfoBean
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.ui.adapter.NewsAdapter
import com.baizan.daka.ui.contract.NewsContract
import com.baizan.daka.ui.presenter.NewsPresenter
import kotlinx.android.synthetic.main.act_base_list.*

class NewsListActivtity : BasePageListActivity<NewsPresenter, NewsAdapter>(), NewsContract.View {

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, NewsListActivtity::class.java)
            context.startActivity(intent)
        }
    }

    override fun onRefresh() {
        presenter?.loadNewsList(mCurrentPageNo)
    }

    override fun onLoadMore() {
        presenter?.loadNewsList(mCurrentPageNo)
    }

    override fun initAdapter(): NewsAdapter = NewsAdapter()

    override fun initPresenter(): NewsPresenter = NewsPresenter(this)

    override fun initView() {
        action_bar.setCenterText("新闻公告")
    }

    override fun initData() {
        super.initData()
        adapter?.setOnItemClickListener { adapter, view, position ->
           val  item =adapter.data.get(position);
            item as NewsInfoBean
            mContext?.let {
                NewsDesActivity.start(it,item.id!!)
            }

        }
    }

    override fun start() {
        presenter?.loadNewsList(mCurrentPageNo)
    }

    override fun loadNewsListSuccess(data: BasePageResponse<NewsInfoBean>) {
        getDatasSuccess(data)
    }

    override fun loadNewsListFail() {
        getDatasFail()
    }


}